package com.itheima.sh.controller;

import com.itheima.sh.clients.UserFeignApi;
import com.itheima.sh.pojo.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class FeignController {
    @Autowired
    UserFeignApi userFeignApi;
    @GetMapping("user/{username}")
//    @HystrixCommand(fallbackMethod = "queryByIdFallBack")
    public User finduser(@PathVariable("username") String username){
        if ("itheima".equals(username)) {
            throw new RuntimeException("请求错误");
        }

        User user = userFeignApi.finduser(username);
        return user;
    }

    //降价方法
//    public String queryByIdFallBack() {
//        return "你的网络不稳定，请稍后重试";
//    }
//    public User queryByIdFallBack(String id) {
//        User user = new User();
//        user.setUsername(id);
//        user.setNickName("你的网络不稳定，请稍后重试");
//        return user;
//    }
}
